﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace winSpriteCreator
{
  public delegate void ClickedEventHandler(object sender, EventArgs e);

  //public delegate void ClickedEventHandler(object sender, EventArgs e);
  public partial class ucSquare : UserControl
  {
    public event ClickedEventHandler Clicked;

    public ucSquare()
    {
      InitializeComponent();

      this.DragDrop += new DragEventHandler(ucSquare_DragDrop);
      this.DragEnter += new DragEventHandler(ucSquare_DragEnter);
      this.pictureBox1.Click += new EventHandler(pictureBox1_Click);
    }

    void pictureBox1_Click(object sender, EventArgs e)
    {
      OnClicked(EventArgs.Empty);
    }



    protected virtual void OnClicked(EventArgs e)
    {
      if (Clicked != null)
        Clicked(this, e);
    }

    private void ucSquare_DragEnter(object sender, DragEventArgs e)
    {
      e.Effect = DragDropEffects.Copy;
    }

    private void ucSquare_DragDrop(object sender, DragEventArgs e)
    {
      string[] sname = (string[]) e.Data.GetData(DataFormats.FileDrop);

      CurrentImage = Image.FromFile(sname[0]);

      //CurrentImage = (Bitmap)e.Data.GetData(DataFormats.Bitmap);

    }

    public Image CurrentImage
    {
      get { return this.pictureBox1.Image; }
      set { this.pictureBox1.Image = value; }
    }

    public BorderStyle SquareBorderStyle
    {
      get { return this.BorderStyle; }
      set { this.BorderStyle = value; }
    }

    public int X { get; set; }
    public int Y { get; set; }

    public override bool Equals(object obj)
    {

      ucSquare objSquare = obj as ucSquare;

      if (objSquare != null )
      {
        if (objSquare.X == this.X && objSquare.Y == this.Y)
          return true;
      }

      return false;
    }
  }

  
}
